package com.zhuiYun.project.api.commoditycollection.controller;
import com.zhuiYun.project.api.commoditycollection.entity.dto.CommodityCollectionDTO;
import com.zhuiYun.project.api.commoditycollection.model.CommodityCollectionModel;
import com.zhuiYun.project.api.commoditycollection.service.CommodityCollectionService;
import com.zhuiYun.project.api.handworkdiycollection.model.HandworkDiyCollectionModel;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
* @Author yangze
* @Description TODO 商品收藏
* @Date 2023/4/4 14:47
* @Return
* @param
*/

@RestController
@CrossOrigin
@Api(tags = "用户收藏")
@RequestMapping("/commodityCollection")
@Slf4j
public class CommodityCollectionController extends BaseController {
    @Resource
    private CommodityCollectionService commodityCollectionService;

    /**
    * @Author yangze
    * @Description TODO 查询收藏的商品
    * @Date 2023/4/4 14:46
    * @Return CommonResult
    * @param commodityCollectionDTO
    */
    @GetMapping("/selectCommodityCollection")
    public CommonResult selectCommodityCollection(CommodityCollectionDTO commodityCollectionDTO) throws CommonException{
        CommonResult commonResult = commodityCollectionService.selectByUserId(commodityCollectionDTO);
        return commonResult;
    }
    /**
    * @Author yangze
    * @Description TODO 取消收藏
    * @Date 2023/4/5 14:32
    * @Return commonResult
    * @param id
    */

    @DeleteMapping("/delete")
    public CommonResult deleteById(Integer id) throws CommonException{
        CommonResult commonResult = commodityCollectionService. deleteById(id);
        return commonResult;
    }

    /**
     * @Author yangze
     * @Description 根据用户userid和commodityId商品id取消收藏
     * @Date 2023/4/10 15:19
     * @Return
     * @param commodityCollectionModel
     */
    @PostMapping("/deleteByUserIdAndDiyId")
    public CommonResult deleteByUserIdAndDiyId(@RequestBody CommodityCollectionModel commodityCollectionModel) throws CommonException {
        CommonResult commonResult = commodityCollectionService.deleteByUserIdAndDiyId(commodityCollectionModel);
        return commonResult;
    }
    /**
     * @Author yangze
     * @Description TODO 添加收藏商品
     * @Date 2023/4/5 14:32
     * @Return CommonResult
     * @param commodityCollectionModel
     */
    @PostMapping("/insertCommodityCollection")
    public CommonResult insertCommodityCollection(@RequestBody CommodityCollectionModel commodityCollectionModel) throws CommonException{
        CommonResult commonResult = commodityCollectionService.insertCollection(commodityCollectionModel);
        return commonResult;
    }
    /**
    * @Author yangze
    * @Description  TODO 查询是否收藏 1收藏 0未收藏
    * @Date 2023/4/10 15:37
    * @Return commonResult
    * @param userId,commodityId
    */

    @GetMapping("/selectCollection")
    public CommonResult selectCollection(Integer userId,Integer commodityId) throws CommonException{
        CommonResult commonResult = commodityCollectionService.selectCollection(userId,commodityId);
        return commonResult;
    }

       







}
